#include<stdio.h>
#include<stdlib.h>

typedef struct Node{
    int data;
    struct Node *next;
}Node,*LinkList;

LinkList List_HeadInsert(){
    Node *s;
    int x;
    LinkList L=(Node*)malloc(sizeof(Node));
    L->next=NULL;
    scanf("%d",&x);
    while(x!=9999){
        s=(Node*)malloc(sizeof(Node));
        s->data=x;
        s->next=L->next;
        L->next=s;  
        scanf("%d",&x);
    }
    return L;
}

int main(){
    LinkList L=List_HeadInsert();
    Node *p=L;
    Node *c=L->next;
    int val;
    scanf("%d",&val); 
    while(c!=NULL){
        if(c->data==val){
            Node *t=c;
            c=c->next;
            p->next=c;
            free(t);
        }
        else{
            c=c->next;
            p=p->next;
        }
    }
    Node* f=L->next;
    while ( f!= NULL) {
        printf("%d ",f->data); 
        f=f->next;  
    }
    
    Node* temp;
    while (L != NULL) {
        temp = L;
        L = L->next;
        free(temp);
    }
    

    return 0;
}